package com.atguigu.guilimall.search.controller;

import com.atguigu.guilimall.search.service.MallSearchService;
import com.atguigu.guilimall.search.vo.SearchParam;
import com.atguigu.guilimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
/**
 * 检索服务
 */
@Controller
public class SearchController {
    @Autowired private MallSearchService mallSearchService;
    /**
     * 商品检索功能
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());    //从请求里面获取所有查询条件

        //根据传进来的页面查询参数，去 es 中检索商品
        SearchResult result = mallSearchService.search(param);
        model.addAttribute("result", result);
        return "list";
    }}
